<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Hbase查询</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="/pages/common/header.jsp"%>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/datePicker/WdatePicker.js"></script>
<script type="text/javascript">
var localchannel = "<s:property value="#parameters['channel']"/>";
var localtype = "<s:property value="#parameters['type']"/>";
var localdate = "<s:property value="#parameters['date']"/>";
var localfromCity= "<s:property value="#parameters['fromCity']"/>";
var localtoCity= "<s:property value="#parameters['toCity']"/>";

var gridManager;
var _dialog;
$(function (){
	
	gridManager = PageLoader.initGridPanel();
	
	var myDate=new Date();
	var year =myDate.getFullYear();
	var month =myDate.getMonth()+1;
	if(month<10){
		month="0"+month;
	}
	var day=myDate.getDate();
	if(day<10){
		day="0"+day;
	}
	var hours =myDate.getHours();
	var startTime=year+"-"+month+"-"+day;
	if(hours<10){
		startTime +=" 0"+hours;
	}else{
		startTime +=" "+hours;
	}
	var stopTime=startTime;
	$("#start_ID").val(startTime);
	$("#end_ID").val(stopTime);
	
	var selectUrl="<%=contextPath %>/preprocess-PlaneInfo-listSourceSel.action";
	
	$.ajax({
			url: selectUrl,
			type: 'POST',
			dataType: 'json',
			error: function(){
				alert('渠道列表请求出错');
			},
			success: function(data){
				$('#channel_ID').html('');
				$('#channel_ID').append('<option value="">请选择渠道</option>' );
				$.each(data.listSource, function(idx, e){
					$('#channel_ID').append('<option value='+e.hbaseKey+'>'+e.shortName+'</option>' );
				});
				
				if(null!=localchannel && ""!=localchannel && "undefined"!=localchannel && null!=localdate && ""!=localdate){
					$('#channel_ID').find("option[value='"+localchannel+"']").attr("selected","selected");
					$('#type_ID').find("option[value='"+localtype+"']").attr("selected","selected");
					$("#start_ID").val(localdate+" 00");
					$("#end_ID").val(localdate+" 23");
					$("#fromCity_ID").val(localfromCity);
					$("#toCity_ID").val(localtoCity);
					searchAction();
				}
			}

		});

	 
});

PageLoader = {

 initGridPanel:function(){
	 var g = $("#maingrid").ligerGrid({
         checkbox:true,
         height : '100%',
         rowHeight: 28,//行默认的高度
         headerRowHeight: 30,//表头行的高度
         pageSize : 20,
         onToNext:next,//条件查询方法
         columns: [
                   { display: '抓取渠道', name: 'grabChannelName', width : 160, editor: { type: 'text' }}, 
                   { display: '运营商', name: 'carrierName', width : 160, editor: { type: 'text' }},
                   { display: '抓取时间', name: 'grabDate',width : 150,editor: { type: 'text' },
                 	  		render:function(rowdata){
                           		var s= rowdata.grabDate;
                           		if(s==null){
                           			return;
                           		}
                           		return s.replace("T"," ");
                           }
                   },
                   { display: '航班日期', name:'flightDate',editor:{type:'text'}},
                   { display: '返程日期', name:'returnFlightDate',editor:{type:'text'}},
                   { display: '航班号', name:'flightNo',editor:{type:'text'}},
                   { display: '最低裸价', name:'totalLowestPrice',editor:{type:'text'}},
                   { display: '最低总价', name:'sumLowestPrice',editor:{type:'text'}},
                   { display: '最低税费', name:'totalLowestTaxesPrice',editor:{type:'text'}},
                   { display: '操作',  width: 120, render: function (rowdata, rowindex, value)
                     {
                         var param = '"' + rowdata.rowkey + '"';
                         var h = "<a href='javascript:openDetailsPage(" + param + ")'>查看</a> ";
                         return h;
                     }
                 }
                 ], 
           enabledEdit: false, clickToEdit: false, 
           parms : [
						 {name:"type",value: $("#type_ID").val()},
						 {name:"channel",value: $("#channel_ID").val()},
						 {name:"start",value: $("#start_ID").val()},
						 {name:"end",value: $("#end_ID").val()},
						 {name:"fromCity",value: $("#fromCity_ID").val()},
						 {name:"toCity",value: $("#toCity_ID").val()},
						 {name:"flightDate",value: $("#flightDate_ID").val()},
						 {name:"returnDate",value: $("#returnDate_ID").val()},
                          ],
           url:"<%=contextPath %>/preprocess-PlaneInfo-pageJson.action",
           width: '100%',
    });
	 g.toggleCol("id",false);//隐藏id列
	 return g;
 }
}


//查询方法
function searchAction(){
	
	var channel=$("#channel_ID").val();
	if(null==channel || ""==channel){
		alert("请选择渠道");
		return;
	}
	var start=$("#start_ID").val();
	if(null==start || ""==start){
		alert("请选择开始时间");
		return;
	}
	
     //form validate
   if(!Validator.Validate(document.getElementById("searchForm"),3))return;
//	var param=$("#searchForm").serialize();
	g = $("#maingrid").ligerGrid({
        checkbox:true,
        height : '100%',
        rowHeight: 28,//行默认的高度
        headerRowHeight: 30,//表头行的高度
        pageSize : 20,
        onToNext:next,//条件查询方法
        newPage:'1',
        columns: [
                  { display: '抓取渠道', name: 'grabChannelName',  editor: { type: 'text' }}, 
                  { display: '运营商', name: 'carrierName',  editor: { type: 'text' }},
                  { display: '出发城市', name: 'fromCity',  editor: { type: 'text' }},
                  { display: '到达城市', name: 'toCity',  editor: { type: 'text' }},
                  { display: '抓取时间', name: 'grabDate',width : 150,editor: { type: 'text' },
                	  		render:function(rowdata){
                          		var s= rowdata.grabDate;
                          		if(s==null){
                          			return;
                          		}
                          		return s.replace("T"," ");
                          }
                  },
                  { display: '航班日期', name:'flightDate',editor:{type:'text'}},
                  { display: '返程日期', name:'returnFlightDate',editor:{type:'text'}},
                  { display: '航班号', name:'flightNo',editor:{type:'text'}},
                  { display: '最低裸价', name:'totalLowestPrice',editor:{type:'text'}},
                  { display: '最低总价', name:'sumLowestPrice',editor:{type:'text'}},
                  { display: '最低税费', name:'totalLowestTaxesPrice',editor:{type:'text'}},
                  { display: '操作',  width: 120, render: function (rowdata, rowindex, value)
                    {
                        var param = '"' + rowdata.rowkey + '"';
                        var h = "<a href='javascript:openDetailsPage(" + param + ")'>查看</a> ";
                        return h;
                    }
                }
       ], 
       enabledEdit: false, clickToEdit: false, 
       parms : [
				{name:"type",value: $("#type_ID").val()},
                {name:"channel",value: $("#channel_ID").val()},
         	    {name:"start",value: $("#start_ID").val()},
         	    {name:"end",value: $("#end_ID").val()},
         	    {name:"fromCity",value: $("#fromCity_ID").val()},
         	    {name:"toCity",value: $("#toCity_ID").val()},
         	    {name:"flightDate",value: $("#flightDate_ID").val()},
         	    {name:"returnDate",value: $("#returnDate_ID").val()},
                ],
       url:"<%=contextPath %>/preprocess-PlaneInfo-pageJson.action",
       width: '100%',

   });
	//gridManager.loadServerData(param);/*执行服务器查询*/
}

/*分页条件查询参数*/
function next(){
	
	gridManager.setOptions({
        parms: [
				{name:"type",value: $("#type_ID").val()},
                {name:"channel",value: $("#channel_ID").val()},
         	    {name:"start",value: $("#start_ID").val()},
         	    {name:"end",value: $("#end_ID").val()},
         	    {name:"fromCity",value: $("#fromCity_ID").val()},
         	    {name:"toCity",value: $("#toCity_ID").val()},
         	    {name:"flightDate",value: $("#flightDate_ID").val()},
         	    {name:"returnDate",value: $("#returnDate_ID").val()},
       {}
        ]
    });
}



function openDetailsPage(id){
	var url = "<%=contextPath %>/preprocess-PlaneInfo-view.action?id="+id;
	_dialog = jQuery.ligerDialog.open({
  	    title: '查看',
  	    url:url,
  	    isResize: true,
  	    width: 850, 
  	    height: 500, 
  	    isHidden: false
      });
}
</script>
</head>
<body>
<div style="width:98%;height:100%;padding-left: 5px;">
<br>
<br>
<div class="searchtitle" >
	<!-- search form -->
	<form name="searchForm" id="searchForm" target="_self">
	<table border="0" cellspacing="0" cellpadding="0" class="form2column">
	  <tr>
		  <td class="label">类型:</td>
		  <td> 
		 	<select name="type"  id="type_ID" class="select-common">
				<option value="single">单程</option>
				<option value="double">往返</option>
			</select>
		   </td>
		  
		  <td class="label"> 渠道:</td>
		  <td >
		    <select name="channel"  id="channel_ID" class="select-common">
				<option value="">请选择</option>
			</select> <font color='red'>*</font>
		  </td>
		  
		  <td class="label">开始时间：</td>
		  <td  style="width:250px;">
				<input name="start" type="text"	id="start_ID" style="width: 180px"    
					onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH'})" readonly="readonly"/><font color='red'>*</font>
		  </td>
		  
			<td class="label"> 结束时间：</td>
			<td  style="width:250px;">
				<input name="end" type="text"	id="end_ID" style="width: 180px"    
				onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH'})" readonly="readonly"/>
			</td>
		
	 </tr>
	 
	 <tr>
	 	<td class="label">出发城市：</td>
	 	<td> <input name="fromCity" type="text" id="fromCity_ID" /> </td>
	 	
	 	<td class="label">到达城市：</td>
	 	<td> <input name="toCity" type="text" id="toCity_ID" /> </td>
	 	
	 	 <td class="label">航班日期：</td>
		  <td  style="width:250px;">
				<input name="flightDate" type="text"	id="flightDate_ID" style="width: 180px"    
					onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="readonly"/>
		  </td>
		  
			<td class="label">返程日期：</td>
			<td  style="width:250px;">
				<input name="returnDate" type="text"	id="returnDate_ID" style="width: 180px"    
				onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="readonly"/>
			</td>
	 	
	 	
	 </tr>
	
	 <tr>
	   <td colspan="8" style="text-align: center;"><input id="searchButton" type="button" class="btn-normal" onclick="searchAction()" value="查询" /></td>
	  </tr>
	</table>	
	</form>
</div>
<!-- grid -->
<div id="maingrid"></div> 
</div>
</body>
</html>
